<!--
 * @Descripttion: (人员基本信息数据项说明/Pro_jxry_staffinfo)
 * @version: (1.0)
 * @Author: (admin)
 * @Date: (2024-12-19)
 * @LastEditors: (admin)
 * @LastEditTime: (2024-12-19)
-->
<template>
  <div class="app-container">
    <!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
    <el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth"
      v-show="showSearch" @submit.native.prevent>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 工具区域 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" v-hasPermi="['projxrystaffinfo:add']" plain icon="el-icon-plus" size="mini"
          @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" :disabled="single" v-hasPermi="['projxrystaffinfo:edit']" plain icon="el-icon-edit"
          size="mini" @click="handleUpdate">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" :disabled="multiple" v-hasPermi="['projxrystaffinfo:delete']" plain
          icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 数据区域 -->
    <el-table :data="dataList" v-loading="loading" ref="table" border highlight-current-row @sort-change="sortChange"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column prop="belongMine" label="煤矿编码" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="dwId" label="定位卡(识别卡)编码" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffName" label="姓名" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffId" label="身份证号" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffJobType" label="工种编码" align="center">
        <template slot-scope="scope">
          <dict-tag :options="staffJobTypeOptions" :value="scope.row.staffJobType" />
        </template>
      </el-table-column>
      <el-table-column prop="staffJob" label="职务编码" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffDepart" label="部门" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffBirth" label="出生年月" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffQualification" label="学历" align="center"
        :show-overflow-tooltip="true" />
      <el-table-column prop="staffIsDb" label="是否带班领导" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffIsTz" label="是否特种作业人员" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffPhone" label="电话号码" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffZsCode" label="资格证书编号" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffZsType" label="资格类型名称" align="center" />
      <el-table-column prop="staffZyType" label="作业类别名称" align="center" />
      <el-table-column prop="staffCzName" label="操作项目名称" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffZsSdate" label="资格证有效开始日期" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="staffZsEdate" label="资格证有效结束日期" align="center" :show-overflow-tooltip="true" />

      <el-table-column label="操作" align="center" width="140">
        <template slot-scope="scope">
          <el-button size="mini"  type="success" icon="el-icon-edit" title="编辑"
            @click="handleUpdate(scope.row)"></el-button>
          <el-button size="mini" type="danger" icon="el-icon-delete" title="删除"
            @click="handleDelete(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination class="mt10" background :total="total" :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改人员基本信息数据项说明对话框 -->
    <el-dialog :title="title" :lock-scroll="false" :visible.sync="open">
      <el-form ref="form" :model="form" :rules="rules" :label-width="formLabelWidth">
        <el-row :gutter="20">

          <el-col :lg="12">
            <el-form-item label="煤矿编码" prop="belongMine">
              <el-input style="width: 208px;" v-model="form.belongMine" placeholder="请输入煤矿编码" disabled />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="姓名" prop="staffName">
              <el-input style="width: 208px;" v-model="form.staffName" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="定位卡编码" prop="dwId">
              <el-input style="width: 208px;" v-model="form.dwId" placeholder="请输入定位卡(识别卡)编码" />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="身份证号" prop="staffId">
              <el-input style="width: 208px;" v-model="form.staffId" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="工种" prop="staffJobType">
              <el-select style="width: 208px;" v-model="form.staffJobType" placeholder="请选择工种">
                <el-option v-for="item in staffJobTypeOptions" :key="item.dictValue" :label="item.dictLabel"
                  :value="item.dictValue"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="职务" prop="staffJob">
              <el-select style="width: 208px;" v-model="form.staffJob" placeholder="请选择工种">
                <el-option v-for="item in staffJobOptions" :key="item.dictValue" :label="item.dictLabel"
                  :value="item.dictValue"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="部门" prop="staffDepart">
              <el-input style="width: 208px;" v-model="form.staffDepart" placeholder="请输入部门" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="出生年月" prop="staffBirth">
              <el-date-picker style="width: 208px;" v-model="form.staffBirth" type="date"
                placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="学历" prop="staffQualification">
              <el-select style="width: 208px;" v-model="form.staffQualification" placeholder="请选择学历">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="是否带班领导" prop="staffIsDb">
              <el-select style="width: 208px;" v-model="form.staffIsDb" placeholder="请选择学历">
                <el-option v-for="item in Isoptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="是否特种作业人员" prop="staffIsTz">
              <el-select style="width: 208px;" v-model="form.staffIsTz" placeholder="请选择学历"
                @change="handleOptionChange">
                <el-option v-for="item in Isoptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="电话号码" prop="staffPhone">
              <el-input style="width: 208px;" v-model="form.staffPhone" placeholder="请输入电话号码" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="资格证书编号" prop="staffZsCode">
              <el-input style="width: 208px;" v-model="form.staffZsCode" placeholder="请输入资格证书编号" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="资格类型名称" prop="staffZsType">
              <el-input style="width: 208px;" v-model="form.staffZsType" placeholder="请输入资格类型名称" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="作业类别名称" prop="staffZyType" :required="isHaveTo">
              <el-input style="width: 208px;" v-model="form.staffZyType" placeholder="请输入作业类别名称" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="操作项目名称" prop="staffCzName">
              <el-input style="width: 208px;" v-model="form.staffCzName" placeholder="请输入操作项目名称" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="资格证有效开始日期" prop="staffZsSdate">
              <el-date-picker style="width: 208px;" v-model="form.staffZsSdate" type="date"
                placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="资格证有效结束日期" prop="staffZsEdate">
              <el-date-picker style="width: 208px;" v-model="form.staffZsEdate" type="date"
                placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<script>
import {
  listProJxryStaffinfo,
  addProJxryStaffinfo,
  delProJxryStaffinfo,
  updateProJxryStaffinfo,
  getProJxryStaffinfo,
} from '@/api/project/proJxryStaffinfo.js';

export default {
  name: "projxrystaffinfo",
  data() {

    // 验证活动名称的函数
    let validateName = (rule, value, callback) => {
      // 当活动名称为空值且为必填时，抛出错误，反之通过校验
      if (this.form.staffIsTz === '' && this.isHaveTo) {
        callback(new Error('请输入作业类别名称'))
      } else {
        callback()
      }
    }

    return {
      isHaveTo: false,
      labelWidth: "160px",
      formLabelWidth: "160px",
      staffJobTypeOptions: [],
      staffJobOptions: [],
      Isoptions: [{
        value: '1',
        label: '是'
      }, {
        value: '0',
        label: '否'
      }],
      //学历 汉字标识，从、、、、、 、其他选择
      options: [{
        value: '研究生',
        label: '研究生'
      }, {
        value: '本科',
        label: '本科'
      }, {
        value: '专科',
        label: '专科'
      }, {
        value: '高中',
        label: '高中'
      }, {
        value: '中专',
        label: '中专'
      }, {
        value: '初中',
        label: '初中'
      }, {
        value: '其他',
        label: '其他'
      }],
      // 选中id数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sort: undefined,
        sortType: undefined,
      },
      // 弹出层标题
      title: "",
      // 操作类型 1、add 2、edit
      opertype: 0,
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 数据列表
      dataList: [],
      // 总记录数
      total: 0,
      // 提交按钮是否显示
      btnSubmitVisible: true,
      // 表单校验
      rules: {
        belongMine: [{ required: true, message: '煤矿编码不能为空', trigger: 'blur' }],
        dwId: [{ required: true, message: '定位卡(识别卡)编码不能为空', trigger: 'blur' }],
        staffName: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
        staffId: [{ required: true, message: '身份证号不能为空', trigger: 'blur' }],
        staffJobType: [{ required: true, message: '工种编码不能为空', trigger: 'blur' }],
        staffJob: [{ required: true, message: '职务不能为空', trigger: 'blur' }],

        staffDepart: [{ required: true, message: '部门不能为空', trigger: 'blur' }],
        staffBirth: [{ required: true, message: '出生年月不能为空', trigger: 'blur' }],
        staffQualification: [{ required: true, message: '学历不能为空', trigger: 'blur' }],
        staffIsDb: [{ required: true, message: '是否带班领导不能为空', trigger: 'blur' }],
        staffIsTz: [{ required: true, message: '是否特种作业人员不能为空', trigger: 'blur' }],
        staffPhone: [{ required: true, message: '电话号码不能为空', trigger: 'blur' }],
        staffZsCode: [{ required: true, message: '资格证书编号不能为空', trigger: 'blur' }],
        staffZsType: [{ required: true, message: '资格类型名称不能为空', trigger: 'blur' }],
        staffZyType: [{ required: true, message: '作业类别名称不能为空', trigger: 'blur' }],

        staffCzName: [{ required: true, message: '操作项目名称不能为空', trigger: 'blur' }],
        staffZsSdate: [{ required: true, message: '资格证有效开始日期不能为空', trigger: 'blur' }],
        staffZsEdate: [{ required: true, message: '资格证有效结束日期 不能为空', trigger: 'blur' }],
      },
    };
  },
  created() {
    // 列表数据查询
    this.getList();
    //“sys_staffjobtype”
    this.getDicts('sys_staffjobtype').then((response) => {
      this.staffJobTypeOptions = response.data
    })
    this.getDicts('sys_staffjoboptions').then((response) => {
      this.staffJobOptions = response.data
    })
  },
  methods: {
    //必填项
    handleOptionChange() {
      if (this.form.staffIsTz === '1') {
        this.rules.staffZsCode[0].required = true;
        this.rules.staffZsType[0].required = true;
        this.rules.staffCzName[0].required = true;
        this.rules.staffZyType[0].required = true;
      } else {
        this.rules.staffZsCode[0].required = false;
        this.rules.staffZsType[0].required = false;
        this.rules.staffCzName[0].required = false;
        this.rules.staffZyType[0].required = false;
      }
      this.$refs.form.validateField('input');
    },
    // 查询数据
    getList() {
      this.loading = true;
      listProJxryStaffinfo(this.queryParams).then(res => {
        if (res.code == 200) {
          this.dataList = res.data.result;
          this.total = res.data.totalNum;
          this.loading = false;
        }
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 重置数据表单
    reset() {
      this.form = {
        belongMine: undefined,
        id: undefined,
        dwId: undefined,
        staffName: undefined,
        staffId: undefined,
        staffJobType: undefined,
        staffJob: undefined,
        staffDepart: undefined,
        staffBirth: undefined,
        staffQualification: undefined,
        staffIsDb: undefined,
        staffIsTz: undefined,
        staffPhone: undefined,
        staffZsCode: undefined,
        staffZsType: undefined,
        staffZyType: undefined,
        staffCzName: undefined,
        staffZsSdate: undefined,
        staffZsEdate: undefined,
        stateFlag: undefined,
        isDelete: undefined,
        createTime: undefined,
        updateTime: undefined,
        uuid: undefined,
      };
      this.resetForm("form");
    },
    // 重置查询操作
    resetQuery() {
      this.timeRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1
      this.multiple = !selection.length;
    },
    // 自定义排序
    sortChange(column) {
      if (column.prop == null || column.order == null) {
        this.queryParams.sort = undefined;
        this.queryParams.sortType = undefined;
      } else {
        this.queryParams.sort = column.prop;
        this.queryParams.sortType = column.order;
      }

      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.getbelongMine().then(res=>{
      if(res.code==210){
        this.$message({
          message: '请先在企业信息管理中添加煤矿编码',
          type: 'warning'
        });
      }else{
      this.reset();
      this.form.belongMine=res.data.sysCode;
      this.open = true;
      this.title = "添加";
      this.opertype = 1;

      }
    });

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const Ids = row.id || this.ids;

      this.$confirm('是否确认删除参数编号为"' + Ids + '"的数据项？')
        .then(function () {
          return delProJxryStaffinfo(Ids);
        })
        .then(() => {
          this.handleQuery();
          this.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.getbelongMine().then(res=>{
      if(res.code==210){
        this.$message({
          message: '请先在企业信息管理中添加煤矿编码',
          type: 'warning'
        });
      }else{
        this.reset();
      const id = row.id || this.ids;
      getProJxryStaffinfo(id).then((res) => {
        const { code, data } = res;
        if (code == 200) {
          this.open = true;
          this.title = "修改数据";
          this.opertype = 2;

          this.form = {
            ...data,
          };
        }
      });

      }
    });

    },

    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log(JSON.stringify(this.form));

          if (this.form.id != undefined && this.opertype === 2) {
            updateProJxryStaffinfo(this.form)
              .then((res) => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .catch((err) => {
                //TODO 错误逻辑
              });
          } else {
            addProJxryStaffinfo(this.form)
              .then((res) => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .catch((err) => {
                //TODO 错误逻辑
              });
          }
        }
      });
    },
  },
};
</script>